package br.com.infnet.formularioeletronico.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConexaoJDBC {

    private static Connection con;

    public static Connection getConexao() throws ClassNotFoundException {
        
        String driver = "org.postgresql.Driver";
        String url = "jdbc:postgresql://localhost:5432/postgres";
        String login = "postgres";
        String senha = "postgres";
        
        try {
            
            Class.forName(driver);
            con = DriverManager.getConnection(url, login, senha);
            
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return con;
    }

    public static void fecharConexao() {
        try {

            if (con != null && !con.isClosed()) {

                con.close();
            }
        } catch (Exception e) {
            //deixado propositalmente em branco
        }
    }
}
